// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';

const routeRequest = {
    // route请求的基本url
    BASE_URL: confing.PRO_URL + "/route",
    // 请求的API
    list(page = 1, limit = 10, route, callbcak) {
        // url
        let url = this.BASE_URL + "/list?page=" + page +
            "&limit=" + limit;
        if (route) {
            if (route.routeCode) {
                url += "&routeCode=" + route.routeCode;
            }
            if (route.routeName) {
                url += "&routeName=" + route.routeName;
            }
            if (route.enableFlag) {
                url += "&enableFlag=" + route.enableFlag;
            }
        }
        // 发送请求
        request.get(url, callbcak);
    },
    /**
     * 新增工艺流程
     * @param {*} route 
     * @param {*} callbcak 
     */
    save(route, callbcak) {
        if (route) {
            request.post(this.BASE_URL + "/save", route, callbcak);
        }
    },
    // 生成生产工单编号
    genRouteCode(callback) {
        request.get(this.BASE_URL + "/gen", callback);
    },
    /**
     * 根据ID删除工艺流程
     * @param {*} routeId 
     * @param {*} callback 
     */
  delete(routeId, callback) {
    request.delete(this.BASE_URL + "/delete?routeId=" + routeId, callback);
  },
 /**
  * 通过id查询工艺路线信息
  * @param {*} routeId 
  * @param {*} callback 
  */
  get(routeId, callback) {
    if (routeId) {
      let url = this.BASE_URL + "/get?routeId=" + routeId;
      request.get(url, callback);
    }
  },
  /**
   * 根据ID编辑工艺流程信息
   * @param {*} route 
   * @param {*} callback 
   */
  edit(route, callback) {
    if (route != undefined && route.routeId != undefined) {
      request.put(this.BASE_URL + "/update", route, callback);
    }
  },
  

}
// 将routeRequest暴漏出去
export default routeRequest;